package com.tulingxueyuan.order.service.impl;

import com.tulingxueyuan.order.api.Stockservice;
import com.tulingxueyuan.order.mapper.OrderMapper;
import com.tulingxueyuan.order.pojo.Order;
import com.tulingxueyuan.order.service.OrderService;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;

/***
 * @Author 徐庶   QQ:1092002729
 * @Slogan 致敬大师，致敬未来的你
 */
@Service
public class OrderServiceImpl implements OrderService {


    @Autowired
    OrderMapper orderMapper;

    @Autowired
    Stockservice stockservice;

    /**
     * 下单
     * @return
     */
    @GlobalTransactional
    @Override
    public Order create(Order order) {
        // 插入能否成功？ 不能成功
        orderMapper.insert(order);
        // 扣减库存 能否成功？ 成功
        stockservice.reduct(order.getProductId());
        // 异常
        int a=1/0;
        return order;
    }
}
